package Point.Double;

import org.junit.Test;

/**
 * 有序 -> 对撞指针
 *
 *
 * [ 蒙了，在注释中简单试一下 ]
 * 1 2 3 4 5
 * 0 1 2 3 4
 * tar=2
 * 2 - 0 1
 * 0 - 1 1
 *
 * -> 所以 w left 带= right
 */
public class BinarySearch704 {
    public int search(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(nums[mid] == target)
                return mid;
            else if(nums[mid] < target)
                left = mid + 1; // 判的mid，所以扔掉mid
            else
                right = mid - 1;
        }
        return -1;
    }
    @Test
    public void test(){
        int[] nums = new int[]{-1,0,3,5,9,12};
        System.out.println(search(nums, 9));
    }
}
